package com.kinyx.framework.utils;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.util.Calendar;

import org.junit.Test;

import com.kinyx.framework.Configs;

public class KCalendarUtils_Tester_ {

	@Test
	public void test1() {
		assertTrue(KCalendarUtils.isWorkDay("20180206"));
		assertFalse(KCalendarUtils.isOffDay("20180206"));

		assertTrue(KCalendarUtils.isWorkDay("20180206", Calendar.TUESDAY));
		assertFalse(KCalendarUtils.isOffDay("20180206", Calendar.TUESDAY));

		assertFalse(KCalendarUtils.isWorkDay("20180206", Calendar.MONDAY, Calendar.WEDNESDAY, Calendar.THURSDAY, Calendar.FRIDAY, Calendar.SATURDAY, Calendar.SUNDAY));
		assertTrue(KCalendarUtils.isOffDay("20180206", Calendar.MONDAY, Calendar.WEDNESDAY, Calendar.THURSDAY, Calendar.FRIDAY, Calendar.SATURDAY, Calendar.SUNDAY));
	}

	@Test
	public void test2() {
		assertEquals("20180205", KDateTimeUtils.toString(KCalendarUtils.getFirstDayOfWeek("20180206", Calendar.MONDAY), Configs.default_KCalendarUtils_datePattern));
		assertEquals("20180206", KDateTimeUtils.toString(KCalendarUtils.getFirstDayOfWeek("20180206", Calendar.TUESDAY), Configs.default_KCalendarUtils_datePattern));
		assertEquals("20180131", KDateTimeUtils.toString(KCalendarUtils.getFirstDayOfWeek("20180206", Calendar.WEDNESDAY), Configs.default_KCalendarUtils_datePattern));
		assertEquals("20180201", KDateTimeUtils.toString(KCalendarUtils.getFirstDayOfWeek("20180206", Calendar.THURSDAY), Configs.default_KCalendarUtils_datePattern));
		assertEquals("20180202", KDateTimeUtils.toString(KCalendarUtils.getFirstDayOfWeek("20180206", Calendar.FRIDAY), Configs.default_KCalendarUtils_datePattern));
		assertEquals("20180203", KDateTimeUtils.toString(KCalendarUtils.getFirstDayOfWeek("20180206", Calendar.SATURDAY), Configs.default_KCalendarUtils_datePattern));
		assertEquals("20180204", KDateTimeUtils.toString(KCalendarUtils.getFirstDayOfWeek("20180206", Calendar.SUNDAY), Configs.default_KCalendarUtils_datePattern));

		assertEquals("20180211", KDateTimeUtils.toString(KCalendarUtils.getLastDayOfWeek("20180206", Calendar.MONDAY), Configs.default_KCalendarUtils_datePattern));
		assertEquals("20180212", KDateTimeUtils.toString(KCalendarUtils.getLastDayOfWeek("20180206", Calendar.TUESDAY), Configs.default_KCalendarUtils_datePattern));
		assertEquals("20180206", KDateTimeUtils.toString(KCalendarUtils.getLastDayOfWeek("20180206", Calendar.WEDNESDAY), Configs.default_KCalendarUtils_datePattern));
		assertEquals("20180207", KDateTimeUtils.toString(KCalendarUtils.getLastDayOfWeek("20180206", Calendar.THURSDAY), Configs.default_KCalendarUtils_datePattern));
		assertEquals("20180208", KDateTimeUtils.toString(KCalendarUtils.getLastDayOfWeek("20180206", Calendar.FRIDAY), Configs.default_KCalendarUtils_datePattern));
		assertEquals("20180209", KDateTimeUtils.toString(KCalendarUtils.getLastDayOfWeek("20180206", Calendar.SATURDAY), Configs.default_KCalendarUtils_datePattern));
		assertEquals("20180210", KDateTimeUtils.toString(KCalendarUtils.getLastDayOfWeek("20180206", Calendar.SUNDAY), Configs.default_KCalendarUtils_datePattern));
	}

	@Test
	public void test3() {
		assertEquals("20180201", KDateTimeUtils.toString(KCalendarUtils.getFirstDayOfMonth("20180206"), Configs.default_KCalendarUtils_datePattern));
		assertEquals("20180201", KDateTimeUtils.toString(KCalendarUtils.getFirstDayOfMonth("20180201"), Configs.default_KCalendarUtils_datePattern));
		assertEquals("20180201", KDateTimeUtils.toString(KCalendarUtils.getFirstDayOfMonth("20180228"), Configs.default_KCalendarUtils_datePattern));

		assertEquals("20180228", KDateTimeUtils.toString(KCalendarUtils.getLastDayOfMonth("20180206"), Configs.default_KCalendarUtils_datePattern));
		assertEquals("20180228", KDateTimeUtils.toString(KCalendarUtils.getLastDayOfMonth("20180201"), Configs.default_KCalendarUtils_datePattern));
		assertEquals("20180228", KDateTimeUtils.toString(KCalendarUtils.getLastDayOfMonth("20180228"), Configs.default_KCalendarUtils_datePattern));
	}

	@Test
	public void test4() {
		// 20180101
		assertEquals(1, KCalendarUtils.getWeekOfYear("20180101", Calendar.MONDAY));
		assertEquals(1, KCalendarUtils.getWeekOfYear("20180101", Calendar.TUESDAY));
		assertEquals(1, KCalendarUtils.getWeekOfYear("20180101", Calendar.WEDNESDAY));
		assertEquals(1, KCalendarUtils.getWeekOfYear("20180101", Calendar.THURSDAY));
		assertEquals(1, KCalendarUtils.getWeekOfYear("20180101", Calendar.FRIDAY));
		assertEquals(1, KCalendarUtils.getWeekOfYear("20180101", Calendar.SATURDAY));
		assertEquals(1, KCalendarUtils.getWeekOfYear("20180101", Calendar.SUNDAY));
		// 20180102
		assertEquals(1, KCalendarUtils.getWeekOfYear("20180102", Calendar.MONDAY));
		assertEquals(2, KCalendarUtils.getWeekOfYear("20180102", Calendar.TUESDAY));
		assertEquals(1, KCalendarUtils.getWeekOfYear("20180102", Calendar.WEDNESDAY));
		assertEquals(1, KCalendarUtils.getWeekOfYear("20180102", Calendar.THURSDAY));
		assertEquals(1, KCalendarUtils.getWeekOfYear("20180102", Calendar.FRIDAY));
		assertEquals(1, KCalendarUtils.getWeekOfYear("20180102", Calendar.SATURDAY));
		assertEquals(1, KCalendarUtils.getWeekOfYear("20180102", Calendar.SUNDAY));
		// 20180206
		assertEquals(6, KCalendarUtils.getWeekOfYear("20180206", Calendar.MONDAY));
		assertEquals(7, KCalendarUtils.getWeekOfYear("20180206", Calendar.TUESDAY));
		assertEquals(6, KCalendarUtils.getWeekOfYear("20180206", Calendar.WEDNESDAY));
		assertEquals(6, KCalendarUtils.getWeekOfYear("20180206", Calendar.THURSDAY));
		assertEquals(6, KCalendarUtils.getWeekOfYear("20180206", Calendar.FRIDAY));
		assertEquals(6, KCalendarUtils.getWeekOfYear("20180206", Calendar.SATURDAY));
		assertEquals(6, KCalendarUtils.getWeekOfYear("20180206", Calendar.SUNDAY));
	}

}
